import React, { useEffect, useState } from 'react'
import PubSub  from 'pubsub-js'
export default function C() {
  //声明状态
  let [v, setV] = useState('');
  //useEffect
  useEffect(() => {     
    PubSub.subscribe('content', (channel, data) => {
      console.log('ccc');
      //更新状态 
      setV(data);
    });
    //返回一个函数
    return () => {
      //取消订阅
      PubSub.unsubscribe('content');
    }
  }, [])
  
  return (
    <div style={{width: 300, height: 200, border: 'solid 1px #252'}}>{v}</div>
  )
}
